package com.study.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author MI
 * @version 1.0
 * @date 2020/10/25 10:40
 */
@RestController
@RefreshScope//动态刷新
public class NacosConfigurableApplicationConfig {

    @Autowired
    private ConfigurableApplicationContext applicationContext;

    @GetMapping("test-config")
    public String testConfig() {
        return applicationContext.getEnvironment().getProperty("names");
    }

    //可以动态读取配置问价中的信息
    @Value("${names}")
    private String name;

    @GetMapping("test-config2")
    public String testConfig2() {
        return name;
    }
}
